<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script type="text/javascript" src="../js/vue.js"></script>
  <title>监视属性</title>
</head>
<body>
  <div id="root">
    <h2>监视属性案例</h2>
    <hr>
    <h3>今天天气 {{info}}</h3>
    <button @click="changeWeather">变换天气</button>
  </div>
  <script type="text/javascript">
    Vue.config.productionTip = false 
    const vm = new Vue({
      el: '#root',
      data:{
        isHost:true
      },
      computed: {
        info() {
          return this.isHost?'炎热':'凉爽'
        }
      },
      methods: {
        changeWeather() {
          this.isHost = !this.isHost
        }
      },
      watch:{
        isHost:{
          immediate:true,
          handler(newValue,oldVlaue){console.log(newValue,oldVlaue);
          }
        }
      }
    })
  </script>
</body>
</html>